package core.communication.message;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public abstract class Message implements Serializable {
	private static final long serialVersionUID = 4723786186406346739L;

	private String destinationURI = null;
	private List<String> path = new ArrayList<String>();
	private Direction direction = null;
	private MessagePriority priority;
	private Long messageToSendDatabaseId;
	private MessageType messageType;
	private Date created;

	public Message() {
		created = Calendar.getInstance().getTime();
	}

	public String getDestinationURI() {
		return destinationURI;
	}

	public void setDestinationURI(String destinationURI) {
		this.destinationURI = destinationURI;
	}

	public void addToPath(String locatorURI) {
		path.add(0, locatorURI);
	}

	public String getURIFromPath() {
		String uri = null;
		if (path.size() != 0) {
			uri = path.get(0);
		}
		return uri;
	}

	public void removeURIFromPath(String uri) {
		if (!path.isEmpty()) {
			if (path.get(0).compareTo(uri) == 0)
				path.remove(0);
		}
	}

	public void updatePath(String locatorURI) {
		if (!path.isEmpty())
			path.remove(0);
		path.add(0, locatorURI);
	}

	public Direction getDirection() {
		return direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public MessagePriority getPriority() {
		return priority;
	}

	public void setPriority(MessagePriority priority) {
		this.priority = priority;
	}

	public Long getMessageToSendDatabaseId() {
		return messageToSendDatabaseId;
	}

	public void setMessageToSendDatabaseId(Long databaseId) {
		this.messageToSendDatabaseId = databaseId;
	}

	public MessageType getMessageType() {
		return messageType;
	}

	public void setMessageType(MessageType messageType) {
		this.messageType = messageType;
	}

	public Date getCreated() {
		return created;
	}

	public void setCreated(Date created) {
		this.created = created;
	}

	public String toString() {
		return getDestinationURI() + " (" + getCreated() + ", " + getMessageType() + ")";
	}
}
